/**	
 * Author : Mht
 * Desc : For 2016 RDM 
 */
package service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import common.TargetDataSource;
import entity.IHS;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Mht
 * @date Jun 15, 2016
 */
@Service
@Slf4j
public class IHSService {

	@Resource
	private JdbcTemplate jdbcTemplate;

	public List<IHS> queryLocalList() {
		return queryList();
	}

	@TargetDataSource(name = "mosaic")
	public List<IHS> queryMosaicList() {
		return queryList();
	}

//	@Transactional
	private List<IHS> queryList() {
		String sql = "SELECT ENTITY_ID,PRODUCTION_YEAR,PRODUCTION_MONTH FROM INTF_P2000";
		return (List<IHS>) jdbcTemplate.query(sql, new RowMapper<IHS>() {

			@Override
			public IHS mapRow(ResultSet rs, int rowNum) throws SQLException {
				IHS stu = new IHS();
				stu.setId(rs.getString("ENTITY_ID"));
				stu.setProductionYear(rs.getString("PRODUCTION_YEAR"));
				stu.setProductionMonth(rs.getString("PRODUCTION_MONTH"));
				log.info("Result : {}", stu.toString());
				return stu;
			}

		});
	}
}
